package org.jeecg.activiti.ActivitClass;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.JavaDelegate;
import org.activiti.engine.runtime.Execution;
import org.jeecg.modules.system.entity.SysUser;
import org.jeecg.modules.system.mapper.SysUserMapper;

public class UserBalance implements JavaDelegate {
    @Override
    public void execute(DelegateExecution execution) {
        SysUserMapper sysUserMapper = SpringContextHolder.getBean(SysUserMapper.class);
        String client_id = String.valueOf(execution.getVariable("client_id"));
        SysUser loginUser = sysUserMapper.selectOne(new QueryWrapper<SysUser>().eq("id", client_id));
        double realBalance=loginUser.getBalance()-Double.parseDouble(execution.getVariable("advance").toString());
        loginUser.setBalance(realBalance);
        sysUserMapper.updateById(loginUser);
    }
}
